<?php
#[引入无限级分类]
$r_url = "admin.php?file=dealer_rg";
#[信息录入]
if($sysAct == "add")
{
	#[判断权限]
	if($_SESSION["admin"]["typer"] != "system" && !$QG_AP["msg_".$sysgroupid])
	{
		Error("对不起，您没有权限操作当前功能","admin.php?file=index");
	}
	Foot("dealer_rg.add.qg");
}
elseif($sysAct == "addok")
{
	$name = $STR->safe($name);
	if(!$name)
	{
		Error("名称不允许为空...","admin.php?file=dealer_rg&act=add");
	}
	//$postdate = $postdate ? strtotime($postdate) : $system_time;#[发布时间]
	//$modifydate = $system_time;#[修改时间，使用系统时间]
	$image = $STR->safe($image);
	//$content = $STR->safe($content);

    $sql = "INSERT INTO ".$prefix."dealer_region(name,image,content,language) VALUES('".$name."','".$image."','".$content."','".$language."')";

	$insert_id = $DB->qgInsert($sql);

	unset($name,$image,$content);
	unset($sql);
	
	Error("信息添加成功...","admin.php?file=dealer_rg&act=add");
}
elseif($sysAct == "modify")
{
	$id = intval($id);
	if(!$id || $id == 0)
	{
		Error("操作不正确，无法取得ID号信息...","admin.php?file=sysgroup&act=list");
	}
	$rs = $DB->qgGetOne("SELECT * FROM ".$prefix."dealer_region WHERE id='".$id."'");
	
	//$content = FckToHtml($rsC["content"]);
	//$fckeditor = FckEditor("content",$content,"LongDefault","400px","100%");
	Foot("dealer_rg.modify.qg");
}
elseif($sysAct == "modifyok")
{
	$id = intval($id);
	if(!$id || $id == 0)
	{
		Error("操作不正确，无法取得ID号信息...","admin.php?file=sysgroup&act=list");
	}
	
	$name = $STR->safe($name);
	if(!$name)
	{
		Error("名称不允许为空...","admin.php?file=dealer_rg&act=add");
	}
	$image = $STR->safe($image);
	//$content = $STR->safe($content);
	
	$sql = "UPDATE ".$prefix."dealer_region SET name='".$name."',image='".$image."',content='".$content."' WHERE id='".$id."'";
	$DB->qgQuery($sql);#[写入数据库]
	unset($sql);
    
	Error("信息编辑成功...","admin.php?file=dealer_rg&act=list");
}
elseif($sysAct == "plset")
{
	$myidlist = $STR->safe($idlist);#[获取IDlist]
	if(!$myidlist)
	{
		Error("信息操作不正确","admin.php?file=dealer_rg&act=list");
	}
	$qgtype = $STR->safe($qgtype);
	if($qgtype == "delete")
	{
		$idarray = explode(",",$myidlist);
		foreach($idarray AS $key=>$value)
		{
			$value = intval($value);
			if($value)
			{
				$DB->qgQuery("DELETE FROM ".$prefix."dealer_region WHERE id='".$value."'");#[删除主题]
				$DB->qgQuery($sql);#[写入数据库]
			}
		}
		Error("批量删除主题完成！","admin.php?file=dealer_rg&act=list");
	}
}
else
{
	#[判断权限]
	if($_SESSION["admin"]["typer"] != "system" && !$QG_AP["msg_".$sysgroupid])
	{
		Error("对不起，您没有权限操作当前功能","admin.php?file=index");
	}
	
	$sql = "SELECT dr.id,dr.name,dr.image,dr.content FROM ".$prefix."dealer_region AS dr WHERE language=".$language;
	$rslist = $DB->qgGetAll($sql,true);
    foreach($rslist AS $key=>$value)
	{
		$sqldl = "SELECT d.id,d.name,d.content FROM ".$prefix."dealer AS d WHERE regionId=".$value['id'];
		
	    $rslist[$key]["dealers"] = $DB->qgGetAll($sqldl, true);
	}
	//print_r($rslist);
	Foot("dealer_rg.list.qg");
}

function get_son_id_array($id,$array,$myid=array())
{
	foreach($array AS $key=>$value)
	{
		if($value["parentid"] == $id)
		{
			$myid[$value["id"]] = $value["id"];
			get_son_id_array($value["id"],$array,$myid);
		}
	}
	return $myid;
}

?>